package com.jia.leetCode;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-16 22:56
 */
public class Pro0477 {
    //统计每位1和0的个数，那么向对该位上的汉明距离为1的个数乘以0的个数，一共计算32为的和
    public int totalHammingDistance(int[] nums) {
        int ans = 0;
        for(int i = 0; i < 32; i ++) {
            int countOne = 0;
            for(int num : nums) {
                if(((num >> i) & 0x1) == 1) {
                    ++countOne;
                }
            }
            ans += countOne * (nums.length - countOne);
        }
        return ans;
    }
}
